<?php
//$Id: Version.php 40 2009-04-02 14:56:47Z vipzhicheng $

/**
 * 查看类的版本信息
 *
 * 只能查看符合Cos规范的类
 *
 */
class Cos_Toolbox_Version
{
    const ID = '$Id: Version.php 40 2009-04-02 14:56:47Z vipzhicheng $';
    const REVISION = 1;
    const AUTHOR = 2;
    const DATE = 4;

    private function __construct() {}
    
    public static function getRevision($className)
    {
        return self::_getVersionInfo($className, self::REVISION);
    }

    public static function getAuthor($className)
    {
        return self::_getVersionInfo($className, self::AUTHOR);
    }

    public static function getDate($className)
    {
        return self::_getVersionInfo($className, self::DATE);
    }

    private static function _getVersionInfo($className, $type)
    {
        eval('$versionInfo = ' . $className . '::ID;');
        $versionInfo = explode(' ', $versionInfo);

        switch ($type) {
            case self::REVISION:
                return $versionInfo[2];
                break;
            case self::AUTHOR:
                return $versionInfo[5];
                break;
            case self::DATE:
                return $versionInfo[3] . ' ' . $versionInfo[4];
                break;
            default:
                return "$className has no version info.";
                break;
        }
    }
}
